package com.example.date;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAdjusters;

public class DateTest2 {
    public static void main(String[] args) {

        LocalDateTime now = LocalDateTime.now();
        //获取当月第一天 0 点
        System.out.println(now.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0));
        //获取当月最后一天 23:59:59 s
        System.out.println(now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59));

        //获取上月第一天 0 点
        System.out.println(now.minusMonths(1).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0));
        //获取上月最后一天 23:59:59 s
        System.out.println(now.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59));
        //获取 2019-11月第一天和最后一天
        System.out.println(now.minusMonths(31).with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0));
        System.out.println(now.minusMonths(31).with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59));

        System.out.println(now.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0).isAfter(
                now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59)
        ));
    }
}
